package cn.com.cifi.mars.service.impl;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.cifi.mars.bean.dto.ProjectByStagesDto;
import cn.com.cifi.mars.bean.vo.supply.ComfirmBaseValueVO;
import cn.com.cifi.mars.bean.vo.supply.CompareDetailVO;
import cn.com.cifi.mars.bean.vo.supply.SupplyPlanVersionCompareVO;
import cn.com.cifi.mars.bean.vo.supply.YearMonthComfirmVO;
import cn.com.cifi.mars.constant.Constants;
import cn.com.cifi.mars.constant.HrOrgTypeEunm;
import cn.com.cifi.mars.constant.IsDeleteEnum;
import cn.com.cifi.mars.constant.MonthEnum;
import cn.com.cifi.mars.constant.OrgTypeEunm;
import cn.com.cifi.mars.constant.SalyTypeEnum;
import cn.com.cifi.mars.constant.StageStatusEnum;
import cn.com.cifi.mars.constant.VersionAttrEnum;
import cn.com.cifi.mars.constant.VersionIdentifyEnum;
import cn.com.cifi.mars.constant.VersionTypeEunm;
import cn.com.cifi.mars.entity.DmDmSupplyCompareDetail;
import cn.com.cifi.mars.entity.StagePartNers;
import cn.com.cifi.mars.entity.SupplyPlanVersion;
import cn.com.cifi.mars.entity.SupplyPlanVersionDetail;
import cn.com.cifi.mars.entity.common.ProjectByStages;
import cn.com.cifi.mars.mapper.mars.DmDmSupplyCompareDetailMapper;
import cn.com.cifi.mars.mapper.mars.StagePartNersMapper;
import cn.com.cifi.mars.mapper.mars.SupplyPlanVersionDetailMapper;
import cn.com.cifi.mars.mapper.mars.SupplyPlanVersionMapper;
import cn.com.cifi.mars.service.DmDmSupplyCompareDetailService;
import cn.com.cifi.mars.service.IdmUserService;
import cn.com.cifi.mars.util.DateUtils;
import cn.com.cifi.mars.util.LocalDateTimeUtils;
import cn.com.cifi.mars.util.NumberUtils;
import cn.com.cifi.mars.util.StrUtils;
import cn.com.cifi.mars.util.UUIDUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author plx
 * @since 2020-02-18
 */
@Service
public class DmDmSupplyCompareDetailServiceImpl extends ServiceImpl<DmDmSupplyCompareDetailMapper, DmDmSupplyCompareDetail> implements DmDmSupplyCompareDetailService {

	@Autowired
	private SupplyPlanVersionMapper supplyPlanVersionMapper;
	
	@Autowired
	private SupplyPlanVersionDetailMapper supplyPlanVersionDetailMapper;
	
	@Autowired
	private DmDmSupplyCompareDetailMapper dmDmSupplyCompareDetailMapper;
	
	@Autowired
	private StagePartNersMapper stagePartNersMapper;
	
	@Autowired
	private IdmUserService idmUserService;
	
	private static final String FIRST_HALF_YEAR_KEY  = "firsthalfYear";
	
	private static final String SECEND_HALF_YEAR_KEY  = "secendhalfYear";
	
	@Override
	public void initSupplyCompareData(String yearMonth) {
		if(StrUtils.isEmpty(yearMonth)) {
			yearMonth = LocalDateTimeUtils.formatTime(LocalDateTime.now(),DateUtils.DATE_JFP_STR);
		}
		String year = String.valueOf(yearMonth.split("-")[0]);
		//清空月度数据
		int count = dmDmSupplyCompareDetailMapper.deleteByDeadlineDate(yearMonth);
		List<Map<String, Object>> baseList = dmDmSupplyCompareDetailMapper.selectBaseData(yearMonth);
		//获取存在版本的所有项目
		List<Map<String, Object>> projectList = supplyPlanVersionMapper.selectProjectList(IsDeleteEnum.NO.getKey());
		if(CollectionUtils.isNotEmpty(projectList)) {
			for(Map<String, Object> pMap : projectList) {
				String projectId = String.valueOf(pMap.get("project_id"));
				String projectCode = String.valueOf(pMap.get("project_code"));
				String projectName = String.valueOf(pMap.get("project_name"));
				//获取年份最新年初预算版
				List<SupplyPlanVersion> budgetList = supplyPlanVersionMapper.selectFirstBudgetVersionListByProjectId(projectId,year,VersionTypeEunm.BUDGET.getKey(),IsDeleteEnum.NO.getKey());
				if(CollectionUtils.isNotEmpty(budgetList)) {
					for(SupplyPlanVersion version : budgetList) {
						//处理预算版数据
						List<SupplyPlanVersionDetail> list = handleBudgetData(version,projectId);
						List<DmDmSupplyCompareDetail> dmDataList = setData(version, list,projectId,projectCode,projectName,year,yearMonth,baseList,VersionIdentifyEnum.ALL_YEAR.getKey());
						//批量保存数据
						dmDmSupplyCompareDetailMapper.insertBatch(dmDataList);
					}
				}
				//获取年份最新年中预算版
				List<SupplyPlanVersion> midBudgetList = supplyPlanVersionMapper.selectMidBudgetVersionListByProjectId(projectId,year,VersionTypeEunm.BUDGET.getKey(),IsDeleteEnum.NO.getKey());
				if(CollectionUtils.isNotEmpty(midBudgetList)) {
					for(SupplyPlanVersion version : midBudgetList) {
						//处理预算版数据
						List<SupplyPlanVersionDetail> list = handleBudgetData(version,projectId);
						List<DmDmSupplyCompareDetail> dmDataList = setData(version, list,projectId,projectCode,projectName,year,yearMonth,baseList,VersionIdentifyEnum.MID_YEAR.getKey());
						//批量保存数据
						dmDmSupplyCompareDetailMapper.insertBatch(dmDataList);
					}
				}
				
				//获取所有月度动态版
				List<SupplyPlanVersion> dynamicList = supplyPlanVersionMapper.selectDynamicVersionListByProjectId(projectId,VersionTypeEunm.DYNAMIC.getKey(),yearMonth,IsDeleteEnum.NO.getKey());
				if(CollectionUtils.isNotEmpty(dynamicList)) {
					for(SupplyPlanVersion version : dynamicList) {
						//处理动态版数据
						List<SupplyPlanVersionDetail>  list = handleDynamicData(version,projectId);
						List<DmDmSupplyCompareDetail> dmDataList = setData(version,list,projectId,projectCode,projectName,year,yearMonth,baseList,null);
						//批量保存数据
						dmDmSupplyCompareDetailMapper.insertBatch(dmDataList);
					}
				}
			}
		}
	}
	
	private List<DmDmSupplyCompareDetail> setData(SupplyPlanVersion version, List<SupplyPlanVersionDetail> list, String projectId, 
			String projectCode, String projectName,String year,String month,List<Map<String, Object>> baseList,String versionIdentify) {
		//分期合作方信息
		StagePartNers stagePart = stagePartNersMapper.selectStagePartnersByProjectFid(version.getProjectfId(), Constants.PARTNER);
		List<DmDmSupplyCompareDetail> dmDataList = Collections.synchronizedList(new ArrayList<>());
		for(SupplyPlanVersionDetail de : list) {
			DmDmSupplyCompareDetail obj = new DmDmSupplyCompareDetail();
			obj.setId(UUIDUtils.create());
			obj.setProjectId(projectId);
			obj.setProjectCode(projectCode);
			obj.setProjectName(projectName);
			obj.setIsFirstOpen(getIsFirstOpen(projectId,baseList));
			obj.setStageId(version.getProjectfId());
			obj.setStageCode(version.getStageCode());
			obj.setStageName(version.getStageName());
			if(stagePart != null) {
				obj.setEquityRatio(stagePart.getEquityRatio());
				obj.setIsOpMarketing(stagePart.getIsOpMarketing());
				obj.setIsAndTable(getStageIsAndTable(stagePart));
				if(de.getType().equals(OrgTypeEunm.ORG_STAGE.getKey())) {
					obj.setExistRoomSale(getStageExistRoomSale(de.getOrgId(),baseList));
				}
			}
			obj.setVersionId(version.getId());
			obj.setVersionName(version.getVersionName());
			obj.setVersionNum(version.getVersionNum());
			obj.setVersionType(version.getVersionType());
			obj.setAffiliationMonth(version.getAffiliationMonth());
			obj.setBudgetYear(version.getBudgetYear());
			obj.setVersionIdentify(versionIdentify);
			obj.setVersionAttr(version.getVersionAttr());
			obj.setVersionCreateTime(version.getCreateTime());
			obj.setVersionUpdateTime(version.getUpdateTime());
			obj.setDeadlineDate(month);
			obj.setdId(de.getId());
			obj.setOrgId(de.getOrgId());
			obj.setOrgCode(de.getOrgCode());
			obj.setOrgName(de.getOrgName());
			obj.setOrgPid(de.getPid());
			obj.setOrgType(de.getType());
			obj.setProProductCode(de.getProProductCode());
			obj.setProProductType(de.getProProductType());
			obj.setBusinessType(de.getBusinessType());
			obj.setBusinessTypeName(de.getBusinessTypeName());
			obj.setFreeType(de.getFreeType());
			obj.setFreeTypeName(de.getFreeTypeName());
			obj.setProType(de.getProType());
			obj.setProTypeName(de.getProTypeName());
			obj.setPlanSupplyDate(de.getSupplyDate());
			obj.setRoomNum(de.getRoomNum());
			obj.setParkingNum(de.getParkingNum());
			obj.setForsaleParkingNum(de.getForsaleParkingNum());
			obj.setSaleArea(de.getSaleArea());
			obj.setHouseCommodityValue(de.getHouseCommodityValue());
			obj.setNotCommodityValue(de.getNotCommodityValue());
			obj.setCommodityValue(de.getCommodityValue());
			obj.setActualSupplyDate(de.getSupplyDateActual());
			obj.setSupplyTimeVirtual(de.getSupplyTimeVirtual());
			obj.setRoomNumActual(de.getRoomNumActual());
			obj.setParkingNumActual(de.getParkingNumActual());
			obj.setForsaleParkingNumActual(de.getForsaleParkingNumActual());
			obj.setAreaActual(de.getAreaActual());
			obj.setHouseCommodityValueActual(de.getHouseCommodityValueActual());
			obj.setCommodityValueActual(de.getCommodityValueActual());
			obj.setNotCommodityValueActual(de.getNotCommodityValueActual());
			obj.setSyncYear(year);
			obj.setCreateTime(LocalDateTime.now());
			dmDataList.add(obj);
		}
		return dmDataList;
	}
	
	private String getStageIsAndTable(StagePartNers stagePart) {
		String isAndTable=stagePart.getPartNerIsAndTable();
		if(StrUtils.isNotEmpty(isAndTable)) {
			return isAndTable.equals("0") ? "否" : "是" ;
		}
		return null;
	}

	private String getStageExistRoomSale(String orgId, List<Map<String, Object>> baseList) {
		if(CollectionUtils.isNotEmpty(baseList)) {
			for(Map<String, Object> map : baseList) {
				String projectfId = String.valueOf(map.get("projectf_id"));
				if(orgId.equals(projectfId)) {
					return String.valueOf(map.get("is_product_exist_room_sale"));
				}
			}
		}
		return null;
	}

	private Integer getIsFirstOpen(String projectId, List<Map<String, Object>> baseList) {
		if(CollectionUtils.isNotEmpty(baseList)) {
			for(Map<String, Object> map : baseList) {
				String projectIdStr = String.valueOf(map.get("project_id"));
				if(projectId.equals(projectIdStr)) {
					return Integer.valueOf(String.valueOf(map.get("is_first_open")));
				}
			}
		}
		return null;
	}

	/**
	 * 
	 * @Description：处理预算版数据
	 * @date：2020年2月15日 下午5:26:04
	 */
	private List<SupplyPlanVersionDetail> handleBudgetData(SupplyPlanVersion version,String projectId) {
		List<SupplyPlanVersionDetail> resData = Collections.synchronizedList(new ArrayList<>());
		List<SupplyPlanVersionDetail> list = supplyPlanVersionDetailMapper.selectByVersionId(version.getId(), IsDeleteEnum.NO.getKey());
		if(version.getVersionAttr().equals(VersionAttrEnum.BEFORE_WARPLAN.getKey())) {
			list = handleInvestmentData(list);
		}
		if(CollectionUtils.isNotEmpty(list)) {
			list.forEach(x->{
				String type = x.getType();
				if(type.equals(OrgTypeEunm.ORG_STAGE.getKey())) {
					x.setPid(projectId);
					resData.add(x);
				}else if(type.equals(OrgTypeEunm.ORG_GROUP.getKey()) || type.equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
					resData.add(x);
				}else if(type.equals(OrgTypeEunm.ORG_BUILD.getKey())) {
					resData.add(x);
				}
			});
		}
		return resData;
	}
	/**
	 * 
	 * @Description：处理动态版数据
	 * @date：2020年2月15日 下午5:26:04
	 */
	private List<SupplyPlanVersionDetail> handleDynamicData(SupplyPlanVersion version,String projectId) {
		List<SupplyPlanVersionDetail> resData = Collections.synchronizedList(new ArrayList<>());
		List<SupplyPlanVersionDetail> list = supplyPlanVersionDetailMapper.selectByVersionId(version.getId(), IsDeleteEnum.NO.getKey());
		if(CollectionUtils.isNotEmpty(list)) {
			list.forEach(x->{
				String type = x.getType();
				if(type.equals(OrgTypeEunm.ORG_STAGE.getKey())) {
					x.setPid(projectId);
					resData.add(x);
				}else if(type.equals(OrgTypeEunm.ORG_GROUP.getKey()) || type.equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
					resData.add(x);
				}else if(type.equals(OrgTypeEunm.ORG_BUILD.getKey())) {
					resData.add(x);
				}
			});
		}
		return resData;
	}
	
	private boolean isValid(String businessType) {
		return businessType.equals(SalyTypeEnum.SALABLE.getKey()) || businessType.equals(SalyTypeEnum.STAGE_SELF_SUSTAINMENT.getKey());
	}
	/**
	 * 
	 * @Description：处理投资版数据(去除批次层级数据后重组)
	 * @date：2020年2月15日 下午5:26:04
	 */
	private List<SupplyPlanVersionDetail> handleInvestmentData(List<SupplyPlanVersionDetail> dataList) {
		return regroupData(dataList);
	}

	/**
	 * 
	 * @Description：数据重组（将批次的子级放到组团下面并移除批次层级）
	 * @author：yyd
	 * @date：2020年2月15日 下午5:25:48
	 */
	private List<SupplyPlanVersionDetail> regroupData(List<SupplyPlanVersionDetail> dataList) {
		Map<String, String> map = new HashMap<String, String>();
		for(SupplyPlanVersionDetail value : dataList) {
			String type = value.getType();
			if(type.equals(OrgTypeEunm.ORG_BATCH.getKey())) {
				String bId = value.getId();
				String bPid = value.getPid();
				map.put(bId, bPid);
			}
		}
		
		List<SupplyPlanVersionDetail> resList = dataList.stream().filter(e -> !OrgTypeEunm.ORG_BATCH.getKey().equals(e.getType())).collect(Collectors.toList());
		
		for(SupplyPlanVersionDetail value : resList) {
			String pid = value.getPid();
			for(Map.Entry<String, String> entry : map.entrySet()){
	            if(entry.getKey().equals(pid)) {
	            	value.setPid(entry.getValue());
	            }
	        }
		}
		
		setSupplyOrgFullpath(resList,Constants.ROOT_NODE_PID);
		
		for(SupplyPlanVersionDetail value : resList) {
			if(value.getType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
				value.setOrgFullPathName(value.getOrgFullPathName()+"/"+value.getBusinessTypeName()+"/"+value.getFreeTypeName()+"/"+value.getProTypeName());
			}
		}
		
		//去重
		List<SupplyPlanVersionDetail> uniqList = resList.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SupplyPlanVersionDetail::getOrgFullPathName))), ArrayList::new));
		
		for(SupplyPlanVersionDetail price : uniqList) {
			prepareData(dataList, price);
		}
		
		return uniqList;
	}
	
	private void prepareData(List<SupplyPlanVersionDetail> dataList, SupplyPlanVersionDetail detail) {
		String orgNames = detail.getOrgFullPathName();
		for(SupplyPlanVersionDetail value : dataList) {
			if(orgNames.equals(value.getOrgFullPathName())) {
				if(detail.getId().equals(value.getId())) {
					continue;
				}
				detail.setRoomNum(NumberUtils.intADD(detail.getRoomNum(), value.getRoomNum()));
				detail.setParkingNum(NumberUtils.intADD(detail.getParkingNum(), value.getParkingNum()));
				detail.setSaleArea(NumberUtils.BigDecimalADD(4, detail.getSaleArea(), value.getSaleArea()));
				detail.setCommodityValue(NumberUtils.BigDecimalADD(4, detail.getCommodityValue(), value.getCommodityValue()));
				detail.setHouseCommodityValue(NumberUtils.BigDecimalADD(4, detail.getHouseCommodityValue(), value.getHouseCommodityValue()));
				detail.setNotCommodityValue(NumberUtils.BigDecimalADD(4, detail.getNotCommodityValue(), value.getNotCommodityValue()));
				
				detail.setRoomNumActual(NumberUtils.intADD(detail.getRoomNumActual(), value.getRoomNumActual()));
				detail.setParkingNumActual(NumberUtils.intADD(detail.getParkingNumActual(), value.getParkingNumActual()));
				detail.setAreaActual(NumberUtils.BigDecimalADD(4, detail.getAreaActual(), value.getAreaActual()));
				detail.setCommodityValueActual(NumberUtils.BigDecimalADD(4, detail.getCommodityValueActual(), value.getCommodityValueActual()));
				detail.setHouseCommodityValueActual(NumberUtils.BigDecimalADD(4, detail.getHouseCommodityValueActual(), value.getHouseCommodityValueActual()));
				detail.setNotCommodityValueActual(NumberUtils.BigDecimalADD(4, detail.getNotCommodityValueActual(), value.getNotCommodityValueActual()));
			}
		}
	}
	
	/**
	 * 
	 * 方法描述：设置供货计划详情全路劲
	 * 创建人：yyd
	 * 创建时间：2019年11月11日 下午7:52:24
	 */
	private List<SupplyPlanVersionDetail> setSupplyOrgFullpath(List<SupplyPlanVersionDetail> supplyPlanValueOrgList, String pid) {
		String fullPath ="";
		String fullPathName = "";
		for(SupplyPlanVersionDetail org : supplyPlanValueOrgList) {
			if(org.getId().equals(pid)) {
				fullPath= org.getOrgFullPath();
				fullPathName = org.getOrgFullPathName();
			}
		}
		
		for(SupplyPlanVersionDetail org : supplyPlanValueOrgList) {
			if(org.getPid().equals(pid)) {
				if(org.getType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
					org.setOrgFullPath(fullPath+"/"+org.getProProductCode()+"/"+org.getOrgCode());
					org.setOrgFullPathName(fullPathName+"/"+org.getProProductType()+"/"+org.getOrgName());
				}else {
					org.setOrgFullPath(fullPath+"/"+org.getOrgCode());
					org.setOrgFullPathName(fullPathName+"/"+org.getOrgName());
				}
				setSupplyOrgFullpath(supplyPlanValueOrgList,org.getId());
			}
		}
		
		return supplyPlanValueOrgList;
	}

	
	private List<DmDmSupplyCompareDetail> getVersionList(List<DmDmSupplyCompareDetail> list,String versionType,String versionIdentify) {
		List<DmDmSupplyCompareDetail> dataList = Collections.synchronizedList(new ArrayList<>());
		for(DmDmSupplyCompareDetail obj : list) {
			if(versionType.equals(obj.getVersionType()) && versionType.equals(VersionTypeEunm.BUDGET.getKey()) && versionIdentify.equals(obj.getVersionIdentify())) {
				dataList.add(obj);
			}else if(versionType.equals(obj.getVersionType()) && versionType.equals(VersionTypeEunm.DYNAMIC.getKey())) {
				dataList.add(obj);
			}
		}
		return dataList;
	}
	
	private List<String> prepareUserDataPermission(String userName) {
        List<String> projectIds = Collections.synchronizedList(new ArrayList<>());
        List<ProjectByStagesDto> dataPermissionList = idmUserService.queryUserDataPermissions(userName);
        if (CollectionUtils.isNotEmpty(dataPermissionList)) {
        	 for (ProjectByStagesDto dto : dataPermissionList) {
                 if (dto.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_31.getKey())) {
                     projectIds.add(dto.getOrgdepid());
                 }
             }
        } 
        return projectIds;
    }
	
	private List<DmDmSupplyCompareDetail> getProjectList(String userName,List<DmDmSupplyCompareDetail> list){
		List<DmDmSupplyCompareDetail> projects = Collections.synchronizedList(new ArrayList<>());
		//获取数据权限
    	List<String> projectIds = prepareUserDataPermission(userName);
    	for(DmDmSupplyCompareDetail detail : list) {
    		String projectId = detail.getProjectId();
    		for(String str : projectIds) {
    			if(str.equals(projectId)) {
    				projects.add(detail);
    			}
    		}
    	}
    	return projects;
	}
	
	private List<DmDmSupplyCompareDetail> getSrageDataList(String stageId,List<DmDmSupplyCompareDetail> projectList) {
		List<DmDmSupplyCompareDetail> stageList = Collections.synchronizedList(new ArrayList<>());
		if(CollectionUtils.isNotEmpty(projectList)) {
			for(DmDmSupplyCompareDetail detail : projectList) {
				if(detail.getStageId().equals(stageId)) {
					stageList.add(detail);
				}
			}
		}
		return stageList;
	}
	
	/**
	 * 
	 * @Description：报表数据整合
	 * @author：yyd
	 * @date：2020年2月15日 下午5:25:48
	 */
	@Override
	public List<SupplyPlanVersionCompareVO> getCompareReport(String deadline,String userName) {
		if(StrUtils.isEmpty(deadline)) {
			deadline = LocalDateTimeUtils.formatTime(LocalDateTime.now(),DateUtils.DATE_JFP_STR);
		}
		String year = deadline.split("-")[0];
		List<SupplyPlanVersionCompareVO> resList = Collections.synchronizedList(new ArrayList<>());
		//项目以上层级数据
		List<ProjectByStages> allOrgList = dmDmSupplyCompareDetailMapper.selectProjectParentList();
		//数据
		List<DmDmSupplyCompareDetail> allDetailList = dmDmSupplyCompareDetailMapper.selectAllList(deadline);
		//有权限的项目数据
		List<DmDmSupplyCompareDetail> projectList = getProjectList(userName,allDetailList);
		//分期
		List<DmDmSupplyCompareDetail> stageList = dmDmSupplyCompareDetailMapper.selectStageList(deadline,StageStatusEnum.CTIVE.getKey());
		
		if(CollectionUtils.isNotEmpty(stageList)) {
			for(DmDmSupplyCompareDetail stage : stageList) {
				String stageId = stage.getStageId();
				List<List<CompareDetailVO>> compareDataList = Collections.synchronizedList(new ArrayList<>());
				//================当前年度对比合计  BEGIN===========================================================
				List<DmDmSupplyCompareDetail> stageDataList = getSrageDataList(stageId,projectList);
				boolean isShow = stageIsShow(deadline,stageDataList);
				if(!isShow) {
					continue;
				}
				//获取年初最新预算版
				List<DmDmSupplyCompareDetail> allYearBudgetList = getVersionList(stageDataList,VersionTypeEunm.BUDGET.getKey(),VersionIdentifyEnum.ALL_YEAR.getKey());
				//获取截止当前日期最新月度动态版
				List<DmDmSupplyCompareDetail> dynamicList = getVersionList(stageDataList,VersionTypeEunm.DYNAMIC.getKey(),"");
				List<CompareDetailVO> allYearBudgetData = parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),"","");
				List<CompareDetailVO> dynamicData = parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),"","");
				//================当前年度对比合计  END==============================================================
				
				//================上半年月度对比合计  BEGIN===========================================================
				List<CompareDetailVO> januaryBudgetData = parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.january.getValue(),"");
				List<CompareDetailVO> januaryDynamicData = parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.january.getValue(),"");
				
				List<CompareDetailVO> februaryBudgetData =parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.february.getValue(),"");
				List<CompareDetailVO> februaryDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.february.getValue(),"");
				
				List<CompareDetailVO> marchBudgetData =parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.march.getValue(),"");
				List<CompareDetailVO> marchDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.march.getValue(),"");
				
				List<CompareDetailVO> aprilBudgetData = parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.april.getValue(),"");
				List<CompareDetailVO> aprilDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.april.getValue(),"");
				
				List<CompareDetailVO> mayBudgetData =parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.may.getValue(),"");
				List<CompareDetailVO> mayDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.may.getValue(),"");
				
				List<CompareDetailVO> juneBudgetData =parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.june.getValue(),"");
				List<CompareDetailVO> juneDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.june.getValue(),"");
				//================上半年月度对比合计  END=============================================================
				
				//================上半年度对比合计  BEGIN============================================================
				List<CompareDetailVO> firsthalfYearBudgetData =  parpareData(allYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),"",FIRST_HALF_YEAR_KEY);
				List<CompareDetailVO> firsthalfYearDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),"",FIRST_HALF_YEAR_KEY);
				//================上半年度对比合计  END==============================================================
				
				//================下半年度对比合计  BEGIN============================================================
				//获取年初最新预算版
				List<DmDmSupplyCompareDetail> midYearBudgetList = getVersionList(stageDataList,VersionTypeEunm.BUDGET.getKey(),VersionIdentifyEnum.MID_YEAR.getKey());
				List<CompareDetailVO> midYearBudgetData =Collections.synchronizedList(new ArrayList<>());
				if(CollectionUtils.isEmpty(midYearBudgetList)) {
					midYearBudgetList = allYearBudgetList;
					midYearBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),"",SECEND_HALF_YEAR_KEY);
				}else {
					midYearBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),"",SECEND_HALF_YEAR_KEY);
				}
				List<CompareDetailVO> midYearDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),"",SECEND_HALF_YEAR_KEY);
				//================下半年度对比合计  END==============================================================
				
				//================下半年月度对比合计  BEGIN===========================================================
				List<CompareDetailVO> julyBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.july.getValue(),"");
				List<CompareDetailVO> julyDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.july.getValue(),"");
				
				List<CompareDetailVO> augustBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.august.getValue(),"");
				List<CompareDetailVO> augustDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.august.getValue(),"");
				
				List<CompareDetailVO> septemberBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.september.getValue(),"");
				List<CompareDetailVO> septemberDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.september.getValue(),"");
				
				List<CompareDetailVO> octoberBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.october.getValue(),"");
				List<CompareDetailVO> octoberDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.october.getValue(),"");
				
				List<CompareDetailVO> novemberBudgetData =  parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.november.getValue(),"");
				List<CompareDetailVO> novemberDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.november.getValue(),"");
				
				List<CompareDetailVO> decemberBudgetData = parpareData(midYearBudgetList,deadline,VersionTypeEunm.BUDGET.getKey(),MonthEnum.december.getValue(),"");
				List<CompareDetailVO> decemberDynamicData =  parpareData(dynamicList,deadline,VersionTypeEunm.DYNAMIC.getKey(),MonthEnum.december.getValue(),"");
				//================下半年月度对比合计  END=============================================================
			
				compareDataList.add(allYearBudgetData);
				compareDataList.add(dynamicData);
				
				compareDataList.add(januaryBudgetData);
				compareDataList.add(januaryDynamicData);
				
				compareDataList.add(februaryBudgetData);
				compareDataList.add(februaryDynamicData);
				
				compareDataList.add(marchBudgetData);
				compareDataList.add(marchDynamicData);
				
				compareDataList.add(aprilBudgetData);
				compareDataList.add(aprilDynamicData);
				
				compareDataList.add(mayBudgetData);
				compareDataList.add(mayDynamicData);
				
				compareDataList.add(juneBudgetData);
				compareDataList.add(juneDynamicData);
				
				compareDataList.add(firsthalfYearBudgetData);
				compareDataList.add(firsthalfYearDynamicData);
				
				compareDataList.add(midYearBudgetData);
				compareDataList.add(midYearDynamicData);
				
				compareDataList.add(julyBudgetData);
				compareDataList.add(julyDynamicData);
				
				compareDataList.add(augustBudgetData);
				compareDataList.add(augustDynamicData);
				
				compareDataList.add(septemberBudgetData);
				compareDataList.add(septemberDynamicData);
				
				compareDataList.add(octoberBudgetData);
				compareDataList.add(octoberDynamicData);
				
				compareDataList.add(novemberBudgetData);
				compareDataList.add(novemberDynamicData);
				
				compareDataList.add(decemberBudgetData);
				compareDataList.add(decemberDynamicData);
				
				//合并层级数据
				List<CompareDetailVO> mergeDataList = mergeData(compareDataList);
				if(CollectionUtils.isNotEmpty(mergeDataList)) {
					for(CompareDetailVO mergeObj : mergeDataList) {
						SupplyPlanVersionCompareVO vo = new SupplyPlanVersionCompareVO();
						String baseFullPathName = mergeObj.getOrgFullPathName();
						vo.setId(mergeObj.getId());
						vo.setCode(mergeObj.getOrgCode());
						vo.setName(mergeObj.getOrgName());
						vo.setPid(mergeObj.getPid());
						vo.setType(mergeObj.getType());
						vo.setIsParking(mergeObj.getIsParking());
						if(mergeObj.getType().equals(OrgTypeEunm.ORG_STAGE.getKey())) {
							//导出字段
							vo.setStageName(mergeObj.getStageName());
							vo.setStageCode(mergeObj.getStageCode());
							vo.setEquityRatio(mergeObj.getEquityRatio());
							vo.setTradersWay(mergeObj.getTradersWay());
							vo.setIsMergeTable(mergeObj.getIsMergeTable());
							vo.setPendingHomeSale(mergeObj.getPendingHomeSale());
						}
						if(mergeObj.getType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
							//导出字段
							vo.setProductTypeName(mergeObj.getProProductType());
							vo.setProductTypeCode(mergeObj.getProProductCode());
						}
						if(mergeObj.getType().equals(OrgTypeEunm.ORG_GROUP.getKey())) {
							//导出字段
							vo.setGroupName(mergeObj.getGroupName());
						}
						vo.setBusinessTypeName(mergeObj.getBusinessTypeName());
						vo.setFreeTypeName(mergeObj.getFreeTypeName());
						vo.setProTypeName(mergeObj.getProTypeName());
						
						YearMonthComfirmVO yearValue = vo.getYearValue();
						List<YearMonthComfirmVO> firstMonthlyValue =getMonthData(year,FIRST_HALF_YEAR_KEY);
						vo.setFirstMonthlyValue(firstMonthlyValue);
						YearMonthComfirmVO firstHalfYearValue = vo.getFirstHalfYearValue();
						YearMonthComfirmVO secondHalfYearValue = vo.getSecondHalfYearValue();
						List<YearMonthComfirmVO> secondMonthlyValue = getMonthData(year,SECEND_HALF_YEAR_KEY);
						vo.setSecondMonthlyValue(secondMonthlyValue);
						//年度对比 数据处理
						prepareYearCompareData(allYearBudgetData,dynamicData,baseFullPathName,yearValue);
						//上半年月度
						prepareMonthlyCompare(januaryBudgetData,januaryDynamicData,baseFullPathName,firstMonthlyValue,MonthEnum.january.getValue());
						prepareMonthlyCompare(februaryBudgetData,februaryDynamicData,baseFullPathName,firstMonthlyValue,MonthEnum.february.getValue());
						prepareMonthlyCompare(marchBudgetData,marchDynamicData,baseFullPathName,firstMonthlyValue,MonthEnum.march.getValue());
						prepareMonthlyCompare(aprilBudgetData,aprilDynamicData,baseFullPathName,firstMonthlyValue,MonthEnum.april.getValue());
						prepareMonthlyCompare(mayBudgetData,mayDynamicData,baseFullPathName,firstMonthlyValue,MonthEnum.may.getValue());
						prepareMonthlyCompare(juneBudgetData,juneDynamicData,baseFullPathName,firstMonthlyValue,MonthEnum.june.getValue());
						//上半年度
						prepareYearCompareData(firsthalfYearBudgetData,firsthalfYearDynamicData,baseFullPathName,firstHalfYearValue);
						//下半年度
						prepareYearCompareData(midYearBudgetData,midYearDynamicData,baseFullPathName,secondHalfYearValue);
						//下半年月度
						prepareMonthlyCompare(julyBudgetData,julyDynamicData,baseFullPathName,secondMonthlyValue,MonthEnum.july.getValue());
						prepareMonthlyCompare(augustBudgetData,augustDynamicData,baseFullPathName,secondMonthlyValue,MonthEnum.august.getValue());
						prepareMonthlyCompare(septemberBudgetData,septemberDynamicData,baseFullPathName,secondMonthlyValue,MonthEnum.september.getValue());
						prepareMonthlyCompare(octoberBudgetData,octoberDynamicData,baseFullPathName,secondMonthlyValue,MonthEnum.october.getValue());
						prepareMonthlyCompare(novemberBudgetData,novemberDynamicData,baseFullPathName,secondMonthlyValue,MonthEnum.november.getValue());
						prepareMonthlyCompare(decemberBudgetData,decemberDynamicData,baseFullPathName,secondMonthlyValue,MonthEnum.december.getValue());
						
						resList.add(vo);
					}
				}
			}
		}
		
		if(CollectionUtils.isEmpty(resList)) {
			return resList;
		}
		
		//去除不存在子级的项目
		List<SupplyPlanVersionCompareVO> resDataList = handleLevelData(resList);
		//数据汇总
		collectData(resDataList,OrgTypeEunm.ORG_GROUP.getKey());
		collectData(resDataList,OrgTypeEunm.ORG_STAGE.getKey());
		//项目
		addProjectData(resDataList,projectList,allOrgList,year);
		collectData(resDataList,OrgTypeEunm.ORG_PRODUCTF.getKey());
		//集团
		addAllGroupData(resDataList,allOrgList,year);
		//城市公司
		collectData(resDataList,OrgTypeEunm.ORG_CITY_COMPANY.getKey());
		//事业部
		collectData(resDataList,OrgTypeEunm.ORG_BUSINESS_DIVISION.getKey());
		//集团
		collectData(resDataList,OrgTypeEunm.ORG_WANDA_GROUP.getKey());
		
		dataHandle(resDataList);
		
		handleAvg(resDataList);
		
		return resDataList;
	}
	
	private boolean stageIsShow(String deadline, List<DmDmSupplyCompareDetail> list) {
		String year = deadline.split("-")[0];
		List<DmDmSupplyCompareDetail> budGetList = Collections.synchronizedList(new ArrayList<>());
		List<DmDmSupplyCompareDetail> dynamicList = Collections.synchronizedList(new ArrayList<>());
		for(DmDmSupplyCompareDetail obj : list) {
			if(obj.getVersionType().equals(VersionTypeEunm.BUDGET.getKey()) && year.equals(obj.getBudgetYear())) {
				budGetList.add(obj);
			}else if(obj.getVersionType().equals(VersionTypeEunm.DYNAMIC.getKey()) && deadline.equals(obj.getDeadlineDate())) {
				dynamicList.add(obj);
			}
		}
		return CollectionUtils.isNotEmpty(budGetList) && CollectionUtils.isNotEmpty(dynamicList);
	}

	private List<SupplyPlanVersionCompareVO> handleLevelData(List<SupplyPlanVersionCompareVO> resList) {
		List<SupplyPlanVersionCompareVO> lastList = Collections.synchronizedList(new ArrayList<>());
		List<SupplyPlanVersionCompareVO> stageList = Collections.synchronizedList(new ArrayList<>());
		List<SupplyPlanVersionCompareVO> stageDataList = Collections.synchronizedList(new ArrayList<>());
		List<SupplyPlanVersionCompareVO> groupList = Collections.synchronizedList(new ArrayList<>());
		List<SupplyPlanVersionCompareVO> groupDataList = Collections.synchronizedList(new ArrayList<>());
		if(CollectionUtils.isNotEmpty(resList)) {
				for(SupplyPlanVersionCompareVO detail : resList) {
					 if(detail.getType().equals(OrgTypeEunm.ORG_STAGE.getKey())) {
		    			 stageList.add(detail);
		    		 }else if(detail.getType().equals(OrgTypeEunm.ORG_GROUP.getKey())) {
		    			 groupList.add(detail);
		    		 }else if(detail.getType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
		    			 lastList.add(detail);
		    		 }
				}
		}
		
		for(SupplyPlanVersionCompareVO vo : groupList) {
			if(!isExistChild(vo.getId(),lastList)) {
				continue;
			}
			groupDataList.add(vo);
		}
		
		for(SupplyPlanVersionCompareVO vo : stageList) {
			if(!isExistChild(vo.getId(),groupDataList)) {
				continue;
			}
			stageDataList.add(vo);
		}
		
		lastList.addAll(groupDataList);
		lastList.addAll(stageDataList);
		return lastList;
	}

	private void handleAvg(List<SupplyPlanVersionCompareVO> resList) {
		for(SupplyPlanVersionCompareVO vo : resList) {
			if(!vo.getType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
				YearMonthComfirmVO yearValue = vo.getYearValue();
				List<YearMonthComfirmVO> firstMonthlyValue = vo.getFirstMonthlyValue();
				YearMonthComfirmVO firstHalfYearValue = vo.getFirstHalfYearValue();
				YearMonthComfirmVO secondHalfYearValue = vo.getSecondHalfYearValue();
				List<YearMonthComfirmVO> secondMonthlyValue = vo.getSecondMonthlyValue();
				
				yearValue.getBudgetValue().setHouseAvgPrice(NumberUtils.divide(yearValue.getBudgetValue().getHousePrice(), yearValue.getBudgetValue().getSaleArea(), 4));
				yearValue.getBudgetValue().setParkingAvgPrice(NumberUtils.divide(yearValue.getBudgetValue().getParkingPrice(), yearValue.getBudgetValue().getParkingNum()==null?null:new BigDecimal(yearValue.getBudgetValue().getParkingNum()), 4));
				yearValue.getDynamicValue().setHouseAvgPrice(NumberUtils.divide(yearValue.getDynamicValue().getHousePrice(), yearValue.getDynamicValue().getSaleArea(), 4));
				yearValue.getDynamicValue().setParkingAvgPrice(NumberUtils.divide(yearValue.getDynamicValue().getParkingPrice(), yearValue.getDynamicValue().getParkingNum()==null?null:new BigDecimal(yearValue.getDynamicValue().getParkingNum()), 4));
				yearValue.getDifferenceValue().setHouseAvgPrice(NumberUtils.divide(yearValue.getDifferenceValue().getHousePrice(), yearValue.getDifferenceValue().getSaleArea(),4));
				yearValue.getDifferenceValue().setParkingAvgPrice(NumberUtils.divide(yearValue.getDifferenceValue().getParkingPrice(), yearValue.getDifferenceValue().getParkingNum()==null?null:new BigDecimal(yearValue.getDifferenceValue().getParkingNum()),4 ));
				
				for(YearMonthComfirmVO first : firstMonthlyValue) {
					first.getBudgetValue().setHouseAvgPrice(NumberUtils.divide(first.getBudgetValue().getHousePrice(), first.getBudgetValue().getSaleArea(), 4));
					first.getBudgetValue().setParkingAvgPrice(NumberUtils.divide(first.getBudgetValue().getParkingPrice(), first.getBudgetValue().getParkingNum()==null?null:new BigDecimal(first.getBudgetValue().getParkingNum()), 4));
					first.getDynamicValue().setHouseAvgPrice(NumberUtils.divide(first.getDynamicValue().getHousePrice(), first.getDynamicValue().getSaleArea(), 4));
					first.getDynamicValue().setParkingAvgPrice(NumberUtils.divide(first.getDynamicValue().getParkingPrice(), first.getDynamicValue().getParkingNum()==null?null:new BigDecimal(first.getDynamicValue().getParkingNum()), 4));
					first.getDifferenceValue().setHouseAvgPrice(NumberUtils.divide(first.getDifferenceValue().getHousePrice(), first.getDifferenceValue().getSaleArea(),4));
					first.getDifferenceValue().setParkingAvgPrice(NumberUtils.divide(first.getDifferenceValue().getParkingPrice(), first.getDifferenceValue().getParkingNum()==null?null:new BigDecimal(first.getDifferenceValue().getParkingNum()),4 ));
				}
				
				firstHalfYearValue.getBudgetValue().setHouseAvgPrice(NumberUtils.divide(firstHalfYearValue.getBudgetValue().getHousePrice(), firstHalfYearValue.getBudgetValue().getSaleArea(), 4));
				firstHalfYearValue.getBudgetValue().setParkingAvgPrice(NumberUtils.divide(firstHalfYearValue.getBudgetValue().getParkingPrice(), firstHalfYearValue.getBudgetValue().getParkingNum()==null?null:new BigDecimal(firstHalfYearValue.getBudgetValue().getParkingNum()), 4));
				firstHalfYearValue.getDynamicValue().setHouseAvgPrice(NumberUtils.divide(firstHalfYearValue.getDynamicValue().getHousePrice(), firstHalfYearValue.getDynamicValue().getSaleArea(), 4));
				firstHalfYearValue.getDynamicValue().setParkingAvgPrice(NumberUtils.divide(firstHalfYearValue.getDynamicValue().getParkingPrice(), firstHalfYearValue.getDynamicValue().getParkingNum()==null?null:new BigDecimal(firstHalfYearValue.getDynamicValue().getParkingNum()), 4));
				firstHalfYearValue.getDifferenceValue().setHouseAvgPrice(NumberUtils.divide(firstHalfYearValue.getDifferenceValue().getHousePrice(), firstHalfYearValue.getDifferenceValue().getSaleArea(),4));
				firstHalfYearValue.getDifferenceValue().setParkingAvgPrice(NumberUtils.divide(firstHalfYearValue.getDifferenceValue().getParkingPrice(), firstHalfYearValue.getDifferenceValue().getParkingNum()==null?null:new BigDecimal(firstHalfYearValue.getDifferenceValue().getParkingNum()),4 ));
				
				secondHalfYearValue.getBudgetValue().setHouseAvgPrice(NumberUtils.divide(secondHalfYearValue.getBudgetValue().getHousePrice(), secondHalfYearValue.getBudgetValue().getSaleArea(), 4));
				secondHalfYearValue.getBudgetValue().setParkingAvgPrice(NumberUtils.divide(secondHalfYearValue.getBudgetValue().getParkingPrice(), secondHalfYearValue.getBudgetValue().getParkingNum()==null?null:new BigDecimal(secondHalfYearValue.getBudgetValue().getParkingNum()), 4));
				secondHalfYearValue.getDynamicValue().setHouseAvgPrice(NumberUtils.divide(secondHalfYearValue.getDynamicValue().getHousePrice(), secondHalfYearValue.getDynamicValue().getSaleArea(), 4));
				secondHalfYearValue.getDynamicValue().setParkingAvgPrice(NumberUtils.divide(secondHalfYearValue.getDynamicValue().getParkingPrice(), secondHalfYearValue.getDynamicValue().getParkingNum()==null?null:new BigDecimal(secondHalfYearValue.getDynamicValue().getParkingNum()), 4));
				secondHalfYearValue.getDifferenceValue().setHouseAvgPrice(NumberUtils.divide(secondHalfYearValue.getDifferenceValue().getHousePrice(), secondHalfYearValue.getDifferenceValue().getSaleArea(),4));
				secondHalfYearValue.getDifferenceValue().setParkingAvgPrice(NumberUtils.divide(secondHalfYearValue.getDifferenceValue().getParkingPrice(), secondHalfYearValue.getDifferenceValue().getParkingNum()==null?null:new BigDecimal(secondHalfYearValue.getDifferenceValue().getParkingNum()),4 ));
				
				
				for(YearMonthComfirmVO second : secondMonthlyValue) {
					second.getBudgetValue().setHouseAvgPrice(NumberUtils.divide(second.getBudgetValue().getHousePrice(), second.getBudgetValue().getSaleArea(), 4));
					second.getBudgetValue().setParkingAvgPrice(NumberUtils.divide(second.getBudgetValue().getParkingPrice(), second.getBudgetValue().getParkingNum()==null?null:new BigDecimal(second.getBudgetValue().getParkingNum()), 4));
					second.getDynamicValue().setHouseAvgPrice(NumberUtils.divide(second.getDynamicValue().getHousePrice(), second.getDynamicValue().getSaleArea(), 4));
					second.getDynamicValue().setParkingAvgPrice(NumberUtils.divide(second.getDynamicValue().getParkingPrice(), second.getDynamicValue().getParkingNum()==null?null:new BigDecimal(second.getDynamicValue().getParkingNum()), 4));
					second.getDifferenceValue().setHouseAvgPrice(NumberUtils.divide(second.getDifferenceValue().getHousePrice(), second.getDifferenceValue().getSaleArea(),4));
					second.getDifferenceValue().setParkingAvgPrice(NumberUtils.divide(second.getDifferenceValue().getParkingPrice(), second.getDifferenceValue().getParkingNum()==null?null:new BigDecimal(second.getDifferenceValue().getParkingNum()),4 ));
				}
				
			}
		}
	}
	
	List<ProjectByStages> projectParentList = null;
	
	private void addProjectData(List<SupplyPlanVersionCompareVO> resList,List<DmDmSupplyCompareDetail> projectIds,List<ProjectByStages> allOrgList,String year) {
		List<SupplyPlanVersionCompareVO> dataList = Collections.synchronizedList(new ArrayList<>());
		for(DmDmSupplyCompareDetail detail : projectIds) {
			//去除不存在子级的项目
			if(!isExistChild(detail.getProjectId(),resList)) {
				continue;
			}
			String projectId=detail.getProjectId();
			projectParentList = Collections.synchronizedList(new ArrayList<>());
			getProjectParentLevel(projectId,allOrgList);
			
			ProjectByStages projectObj = getParentObj(projectParentList,projectId);
			if(projectObj != null) {
				//项目
				SupplyPlanVersionCompareVO vo = new SupplyPlanVersionCompareVO();
				vo.setId(detail.getProjectId());
				vo.setCode(detail.getProjectCode());
				vo.setName(detail.getProjectName());
				vo.setPid(projectObj.getParentOrgid());
				vo.setType(OrgTypeEunm.ORG_PRODUCTF.getKey());
				//导出字段
				vo.setProjectName(detail.getProjectName());
				vo.setProjectCode(detail.getProjectCode());
				vo.setIsFirst(detail.getIsFirstOpen()+"");
				
				List<YearMonthComfirmVO> firstMonthlyValue = getMonthData(year,FIRST_HALF_YEAR_KEY);
				vo.setFirstMonthlyValue(firstMonthlyValue);
				List<YearMonthComfirmVO> secondMonthlyValue = getMonthData(year,SECEND_HALF_YEAR_KEY);
				vo.setSecondMonthlyValue(secondMonthlyValue);
				dataList.add(vo);
				//城市公司
				ProjectByStages city = getParentObj(projectParentList,projectObj.getParentOrgid());
				if(city != null) {
					SupplyPlanVersionCompareVO cityVo = new SupplyPlanVersionCompareVO();
					cityVo.setId(city.getOrgdepid());
					cityVo.setCode(null);
					cityVo.setName(city.getOrgname());
					cityVo.setCityName(city.getOrgname());
					cityVo.setPid(city.getParentOrgid());
					cityVo.setType(OrgTypeEunm.ORG_CITY_COMPANY.getKey());
					List<YearMonthComfirmVO> cFirstMonthlyValue = getMonthData(year,FIRST_HALF_YEAR_KEY);
					cityVo.setFirstMonthlyValue(cFirstMonthlyValue);
					List<YearMonthComfirmVO> cSecondMonthlyValue = getMonthData(year,SECEND_HALF_YEAR_KEY);
					cityVo.setSecondMonthlyValue(cSecondMonthlyValue);
					dataList.add(cityVo);
					//事业部
					ProjectByStages division = getParentObj(projectParentList,city.getParentOrgid());
					if(division != null) {
						SupplyPlanVersionCompareVO divisionVo = new SupplyPlanVersionCompareVO();
						divisionVo.setId(division.getOrgdepid());
						divisionVo.setCode(null);
						divisionVo.setName(division.getOrgname());
						divisionVo.setAreaName(division.getOrgname());
						divisionVo.setPid(division.getParentOrgid());
						divisionVo.setType(OrgTypeEunm.ORG_BUSINESS_DIVISION.getKey());
						List<YearMonthComfirmVO> dFirstMonthlyValue = getMonthData(year,FIRST_HALF_YEAR_KEY);
						divisionVo.setFirstMonthlyValue(dFirstMonthlyValue);
						List<YearMonthComfirmVO> dSecondMonthlyValue = getMonthData(year,SECEND_HALF_YEAR_KEY);
						divisionVo.setSecondMonthlyValue(dSecondMonthlyValue);
						dataList.add(divisionVo);
					}
				}
			}
		}
		
		//去重
		List<SupplyPlanVersionCompareVO> list = dataList.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SupplyPlanVersionCompareVO::getId))), ArrayList::new)
        );
		resList.addAll(list);
	}
	
	private void getProjectParentLevel(String id,List<ProjectByStages> orgList){
		if(CollectionUtils.isNotEmpty(orgList)) {
			for(ProjectByStages org : orgList) {
				String orgId = org.getOrgdepid();
				if(orgId.equals(id)) {
					String pId = org.getParentOrgid();
					projectParentList.add(org);
					getProjectParentLevel(pId,orgList);
				}
			}
		}
	}
	
	
	public boolean isExistChild(String projectId,List<SupplyPlanVersionCompareVO> resList) {
		if(CollectionUtils.isNotEmpty(resList)) {
			for(SupplyPlanVersionCompareVO vo : resList) {
				if(projectId.equals(vo.getPid())) {
					return true;
				}
			}
		}
		return false;
	}
	
	private void addAllGroupData(List<SupplyPlanVersionCompareVO> resList,List<ProjectByStages> allOrgList, String year) {
		for(ProjectByStages obj : allOrgList) {
			if(obj.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_11.getKey())) {
				SupplyPlanVersionCompareVO vo = new SupplyPlanVersionCompareVO();
				vo.setId(obj.getOrgdepid());
				vo.setCode(null);
				vo.setName(obj.getOrgname());
				vo.setPid(Constants.ROOT_NODE_PID);
				vo.setType(OrgTypeEunm.ORG_WANDA_GROUP.getKey());
				List<YearMonthComfirmVO> firstMonthlyValue = getMonthData(year,FIRST_HALF_YEAR_KEY);
				vo.setFirstMonthlyValue(firstMonthlyValue);
				List<YearMonthComfirmVO> secondMonthlyValue = getMonthData(year,SECEND_HALF_YEAR_KEY);
				vo.setSecondMonthlyValue(secondMonthlyValue);
				resList.add(vo);
			}
		}
	}
	
	private List<SupplyPlanVersionCompareVO> dataHandle(List<SupplyPlanVersionCompareVO> dataList) {
		List<SupplyPlanVersionCompareVO> resList = Collections.synchronizedList(new ArrayList<>());
		dataList.forEach(x->{
			String typeTemp = x.getType();
			if(typeTemp.equals(OrgTypeEunm.ORG_STAGE.getKey()) || typeTemp.equals(OrgTypeEunm.ORG_PRODUCTF.getKey()) || typeTemp.equals(OrgTypeEunm.ORG_CITY_COMPANY.getKey())
					|| typeTemp.equals(OrgTypeEunm.ORG_BUSINESS_DIVISION.getKey()) || typeTemp.equals(OrgTypeEunm.ORG_WANDA_GROUP.getKey())){
				resList.add(x);
		    }
		});
		return resList;
	}
	
	public List<YearMonthComfirmVO> getMonthData(String year,String temp) {
		List<YearMonthComfirmVO> list = new ArrayList<>();
		if(temp.equals(FIRST_HALF_YEAR_KEY)) {
			for(int i = Constants.ONE;i <= Constants.SIX; i++) {
				String m="";
				YearMonthComfirmVO vo = new YearMonthComfirmVO();
				if(i<10) {
					m="0"+i;
				}else {
					m=i+"";
				}
				vo.setYearMonth(year+"-"+m);
				list.add(vo);
			}
		}else {
			for(int i = Constants.SEVEN;i <= Constants.TWELVE;i++) {
				String m="";
				YearMonthComfirmVO vo = new YearMonthComfirmVO();
				if(i<10) {
					m="0"+i;
				}else {
					m=i+"";
				}
				vo.setYearMonth(year+"-"+m);
				list.add(vo);
			}
		}
		return list;
	}
	
	private ProjectByStages getParentObj(List<ProjectByStages> allOrgList,String pId) {
		if(CollectionUtils.isNotEmpty(allOrgList)) {
			for(ProjectByStages obj : allOrgList) {
				if(StrUtils.isNotEmpty(pId) && obj.getOrgdepid().equals(pId)) {
					return  obj;
				}
			}
		}
		return null;
	}
	
	/**
	 * 
	 * @Description：数据汇总
	 * @author：yyd
	 * @date：2020年2月14日 下午2:56:28
	 */
	private void collectData(List<SupplyPlanVersionCompareVO> resList,String orgType) {
		if(CollectionUtils.isNotEmpty(resList)) {
			for(SupplyPlanVersionCompareVO vo : resList) {
				String type = vo.getType();
				if(type.equals(orgType)) {
					String id= vo.getId();
					List<SupplyPlanVersionCompareVO> childList = getChildDataList(id,resList);
					collectChildData(childList,vo);
				}
			}
		}
	}
	/**
	 * 
	 * @Description：获取子级数据
	 * @author：yyd
	 * @date：2020年2月15日 下午4:49:07
	 */
	private List<SupplyPlanVersionCompareVO> getChildDataList(String id,List<SupplyPlanVersionCompareVO> resList) {
		List<SupplyPlanVersionCompareVO> list =  Collections.synchronizedList(new ArrayList<>());
		for(SupplyPlanVersionCompareVO vo : resList) {
			String pid = vo.getPid();
			if(pid.equals(id)) {
				list.add(vo);
			}
		}
		return list;
	}
	/**
	 * 
	 * @Description：子级数据汇总到父级
	 * @author：yyd
	 * @date：2020年2月15日 下午4:50:00
	 */
	private void collectChildData(List<SupplyPlanVersionCompareVO> childList,SupplyPlanVersionCompareVO parentObj) {
		if(CollectionUtils.isNotEmpty(childList)) {
			YearMonthComfirmVO parentYearValue = parentObj.getYearValue();
			List<YearMonthComfirmVO> parentFirstMonthlyValue = parentObj.getFirstMonthlyValue();
			YearMonthComfirmVO parentFirstHalfYearValue = parentObj.getFirstHalfYearValue();
			YearMonthComfirmVO parentSecondHalfYearValue = parentObj.getSecondHalfYearValue();
			List<YearMonthComfirmVO> parentSecondMonthlyValue = parentObj.getSecondMonthlyValue();
			for(SupplyPlanVersionCompareVO vo : childList) {
				YearMonthComfirmVO childYearValue = vo.getYearValue();
				List<YearMonthComfirmVO> childFirstMonthlyValue = vo.getFirstMonthlyValue();
				YearMonthComfirmVO childFirstHalfYearValue = vo.getFirstHalfYearValue();
				YearMonthComfirmVO childSecondHalfYearValue = vo.getSecondHalfYearValue();
				List<YearMonthComfirmVO> childSecondMonthlyValue = vo.getSecondMonthlyValue();
				
				yearDataCollect(parentYearValue, childYearValue);
				monthlyDataCollect(parentFirstMonthlyValue,childFirstMonthlyValue);
				yearDataCollect(parentFirstHalfYearValue, childFirstHalfYearValue);
				yearDataCollect(parentSecondHalfYearValue, childSecondHalfYearValue);
				monthlyDataCollect(parentSecondMonthlyValue,childSecondMonthlyValue);
			}
		}
	}
	/**
	 * 
	 * @Description：月度数据汇总处理
	 * @author：yyd
	 * @date：2020年2月15日 下午4:49:07
	 */
	private void monthlyDataCollect(List<YearMonthComfirmVO> parentValueList, List<YearMonthComfirmVO> childValueList) {
		for(YearMonthComfirmVO parentObj : parentValueList) {
			String pMonth = parentObj.getYearMonth();
			ComfirmBaseValueVO pBudgetValue = parentObj.getBudgetValue();
			ComfirmBaseValueVO pDynamicValue = parentObj.getDynamicValue();
			ComfirmBaseValueVO pDifferenceValue = parentObj.getDifferenceValue();
			for(YearMonthComfirmVO childObj : childValueList) {
				String cMonth = childObj.getYearMonth();
				ComfirmBaseValueVO cBudgetValue = childObj.getBudgetValue();
				ComfirmBaseValueVO cDynamicValue = childObj.getDynamicValue();
				ComfirmBaseValueVO cDifferenceValue = childObj.getDifferenceValue();
				if(pMonth.equals(cMonth)) {
					pBudgetValue.setRoomNum(NumberUtils.intADD(pBudgetValue.getRoomNum(),cBudgetValue.getRoomNum()));
					pBudgetValue.setParkingNum(NumberUtils.intADD(pBudgetValue.getParkingNum(),cBudgetValue.getParkingNum()));
					pBudgetValue.setSaleArea(NumberUtils.BigDecimalADD(4,pBudgetValue.getSaleArea(),cBudgetValue.getSaleArea()));
					pBudgetValue.setHousePrice(NumberUtils.BigDecimalADD(4,pBudgetValue.getHousePrice(),cBudgetValue.getHousePrice()));
					pBudgetValue.setParkingPrice(NumberUtils.BigDecimalADD(4,pBudgetValue.getParkingPrice(),cBudgetValue.getParkingPrice()));
					pBudgetValue.setTotalPrice(NumberUtils.BigDecimalADD(4,pBudgetValue.getTotalPrice(),cBudgetValue.getTotalPrice()));
					
					pDynamicValue.setRoomNum(NumberUtils.intADD(pDynamicValue.getRoomNum(),cDynamicValue.getRoomNum()));
					pDynamicValue.setParkingNum(NumberUtils.intADD(pDynamicValue.getParkingNum(),cDynamicValue.getParkingNum()));
					pDynamicValue.setSaleArea(NumberUtils.BigDecimalADD(4,pDynamicValue.getSaleArea(),cDynamicValue.getSaleArea()));
					pDynamicValue.setHousePrice(NumberUtils.BigDecimalADD(4,pDynamicValue.getHousePrice(),cDynamicValue.getHousePrice()));
					pDynamicValue.setParkingPrice(NumberUtils.BigDecimalADD(4,pDynamicValue.getParkingPrice(),cDynamicValue.getParkingPrice()));
					pDynamicValue.setTotalPrice(NumberUtils.BigDecimalADD(4,pDynamicValue.getTotalPrice(),cDynamicValue.getTotalPrice()));
					
					pDifferenceValue.setRoomNum(NumberUtils.intADD(pDifferenceValue.getRoomNum(),cDifferenceValue.getRoomNum()));
					pDifferenceValue.setParkingNum(NumberUtils.intADD(pDifferenceValue.getParkingNum(),cDifferenceValue.getParkingNum()));
					pDifferenceValue.setSaleArea(NumberUtils.BigDecimalADD(4,pDifferenceValue.getSaleArea(),cDifferenceValue.getSaleArea()));
					pDifferenceValue.setHousePrice(NumberUtils.BigDecimalADD(4,pDifferenceValue.getHousePrice(),cDifferenceValue.getHousePrice()));
					pDifferenceValue.setParkingPrice(NumberUtils.BigDecimalADD(4,pDifferenceValue.getParkingPrice(),cDifferenceValue.getParkingPrice()));
					pDifferenceValue.setTotalPrice(NumberUtils.BigDecimalADD(4,pDifferenceValue.getTotalPrice(),cDifferenceValue.getTotalPrice()));
				}
			}
			
		}
	}
	/**
	 * 
	 * @Description：年度数据汇总处理
	 * @author：yyd
	 * @date：2020年2月15日 下午4:49:07
	 */
	private void yearDataCollect(YearMonthComfirmVO parentValue, YearMonthComfirmVO childValue) {
		parentValue.getBudgetValue().setRoomNum(NumberUtils.intADD(parentValue.getBudgetValue().getRoomNum(),childValue.getBudgetValue().getRoomNum()));
		parentValue.getBudgetValue().setParkingNum(NumberUtils.intADD(parentValue.getBudgetValue().getParkingNum(),childValue.getBudgetValue().getParkingNum()));
		parentValue.getBudgetValue().setSaleArea(NumberUtils.BigDecimalADD(4,parentValue.getBudgetValue().getSaleArea(),childValue.getBudgetValue().getSaleArea()));
		parentValue.getBudgetValue().setHousePrice(NumberUtils.BigDecimalADD(4,parentValue.getBudgetValue().getHousePrice(),childValue.getBudgetValue().getHousePrice()));
		parentValue.getBudgetValue().setParkingPrice(NumberUtils.BigDecimalADD(4,parentValue.getBudgetValue().getParkingPrice(),childValue.getBudgetValue().getParkingPrice()));
		parentValue.getBudgetValue().setTotalPrice(NumberUtils.BigDecimalADD(4,parentValue.getBudgetValue().getTotalPrice(),childValue.getBudgetValue().getTotalPrice()));
		
		parentValue.getDynamicValue().setRoomNum(NumberUtils.intADD(parentValue.getDynamicValue().getRoomNum(),childValue.getDynamicValue().getRoomNum()));
		parentValue.getDynamicValue().setParkingNum(NumberUtils.intADD(parentValue.getDynamicValue().getParkingNum(),childValue.getDynamicValue().getParkingNum()));
		parentValue.getDynamicValue().setSaleArea(NumberUtils.BigDecimalADD(4,parentValue.getDynamicValue().getSaleArea(),childValue.getDynamicValue().getSaleArea()));
		parentValue.getDynamicValue().setHousePrice(NumberUtils.BigDecimalADD(4,parentValue.getDynamicValue().getHousePrice(),childValue.getDynamicValue().getHousePrice()));
		parentValue.getDynamicValue().setParkingPrice(NumberUtils.BigDecimalADD(4,parentValue.getDynamicValue().getParkingPrice(),childValue.getDynamicValue().getParkingPrice()));
		parentValue.getDynamicValue().setTotalPrice(NumberUtils.BigDecimalADD(4,parentValue.getDynamicValue().getTotalPrice(),childValue.getDynamicValue().getTotalPrice()));
		
		parentValue.getDifferenceValue().setRoomNum(NumberUtils.intADD(parentValue.getDifferenceValue().getRoomNum(),childValue.getDifferenceValue().getRoomNum()));
		parentValue.getDifferenceValue().setParkingNum(NumberUtils.intADD(parentValue.getDifferenceValue().getParkingNum(),childValue.getDifferenceValue().getParkingNum()));
		parentValue.getDifferenceValue().setSaleArea(NumberUtils.BigDecimalADD(4,parentValue.getDifferenceValue().getSaleArea(),childValue.getDifferenceValue().getSaleArea()));
		parentValue.getDifferenceValue().setHousePrice(NumberUtils.BigDecimalADD(4,parentValue.getDifferenceValue().getHousePrice(),childValue.getDifferenceValue().getHousePrice()));
		parentValue.getDifferenceValue().setParkingPrice(NumberUtils.BigDecimalADD(4,parentValue.getDifferenceValue().getParkingPrice(),childValue.getDifferenceValue().getParkingPrice()));
		parentValue.getDifferenceValue().setTotalPrice(NumberUtils.BigDecimalADD(4,parentValue.getDifferenceValue().getTotalPrice(),childValue.getDifferenceValue().getTotalPrice()));
	}
	/**
	 * 
	 * @Description：年度对比 数据处理
	 * @author：yyd
	 * @date：2020年2月14日 下午2:56:28
	 */
	private void prepareYearCompareData(List<CompareDetailVO> budgetData,List<CompareDetailVO> dynamicData,
			String baseFullPathName,YearMonthComfirmVO yearValue) {
		if(CollectionUtils.isNotEmpty(budgetData)) {
			for(CompareDetailVO budget : budgetData) {
				String fullPathName = budget.getOrgFullPathName();
				if(fullPathName.equals(baseFullPathName)) {
					yearValue.getBudgetValue().setRoomNum(budget.getRoomNum());
					yearValue.getBudgetValue().setParkingNum(budget.getParkingNum());
					yearValue.getBudgetValue().setSaleArea(budget.getSaleArea());
					yearValue.getBudgetValue().setHousePrice(budget.getHousePrice());
					yearValue.getBudgetValue().setParkingPrice(budget.getParkingPrice());
					yearValue.getBudgetValue().setTotalPrice(NumberUtils.BigDecimalADD(4, budget.getHousePrice(), budget.getParkingPrice()));
					yearValue.getBudgetValue().setHouseAvgPrice(NumberUtils.divide(budget.getHousePrice(),budget.getSaleArea(),2));
					yearValue.getBudgetValue().setParkingAvgPrice(NumberUtils.divide(budget.getParkingPrice(),budget.getParkingNum()==null?null:new BigDecimal(budget.getParkingNum()),2));
				}
			}
		}
		if(CollectionUtils.isNotEmpty(dynamicData)) {
			for(CompareDetailVO dynamic : dynamicData) {
				String fullPathName = dynamic.getOrgFullPathName();
				if(fullPathName.equals(baseFullPathName)) {
					yearValue.getDynamicValue().setRoomNum(dynamic.getRoomNum());
					yearValue.getDynamicValue().setParkingNum(dynamic.getParkingNum());
					yearValue.getDynamicValue().setSaleArea(dynamic.getSaleArea());
					yearValue.getDynamicValue().setHousePrice(dynamic.getHousePrice());
					yearValue.getDynamicValue().setParkingPrice(dynamic.getParkingPrice());
					yearValue.getDynamicValue().setTotalPrice(NumberUtils.BigDecimalADD(4, dynamic.getHousePrice(), dynamic.getParkingPrice()));
					yearValue.getDynamicValue().setHouseAvgPrice(NumberUtils.divide(dynamic.getHousePrice(),dynamic.getSaleArea(),2));
					yearValue.getDynamicValue().setParkingAvgPrice(NumberUtils.divide(dynamic.getParkingPrice(),dynamic.getParkingNum()==null?null:new BigDecimal(dynamic.getParkingNum()),2));
				}
			}
		}
		//差异
		Integer budgetRoomNum = yearValue.getBudgetValue().getRoomNum();
		Integer budgetParkingNum = yearValue.getBudgetValue().getParkingNum();
		BigDecimal budgetSaleArea = yearValue.getBudgetValue().getSaleArea();
		BigDecimal budgetHousePrice = yearValue.getBudgetValue().getHousePrice();
		BigDecimal budgetParkingPrice = yearValue.getBudgetValue().getParkingPrice();
		BigDecimal budgetHouseAvgPrice= yearValue.getBudgetValue().getHouseAvgPrice();
		BigDecimal budgetParkingAvgPrice = yearValue.getBudgetValue().getParkingAvgPrice();
		
		Integer dynamicRoomNum = yearValue.getDynamicValue().getRoomNum();
		Integer dynamicParkingNum = yearValue.getDynamicValue().getParkingNum();
		BigDecimal dynamicSaleArea = yearValue.getDynamicValue().getSaleArea();
		BigDecimal dynamicHousePrice = yearValue.getDynamicValue().getHousePrice();
		BigDecimal dynamicParkingPrice = yearValue.getDynamicValue().getParkingPrice();
		BigDecimal dynamicHouseAvgPrice= yearValue.getDynamicValue().getHouseAvgPrice();
		BigDecimal dynamicParkingAvgPrice = yearValue.getDynamicValue().getParkingAvgPrice();
		
		//房源套数差异
      	Integer roomNumDiff = NumberUtils.IntegerSubtract(dynamicRoomNum,budgetRoomNum);
      	Integer parkingNumDiff = NumberUtils.IntegerSubtract(dynamicParkingNum,budgetParkingNum);
      	BigDecimal areaDiff = NumberUtils.subtract(dynamicSaleArea,budgetSaleArea);
      	BigDecimal housePriceDiff = NumberUtils.subtract(dynamicHousePrice,budgetHousePrice);
      	BigDecimal parkingPriceDiff = NumberUtils.subtract(dynamicParkingPrice,budgetParkingPrice);
      	BigDecimal houseAvgPriceDiff = NumberUtils.subtract(dynamicHouseAvgPrice,budgetHouseAvgPrice);
      	BigDecimal parkingAvgPriceDiff = NumberUtils.subtract(dynamicParkingAvgPrice,budgetParkingAvgPrice);
	
      	yearValue.getDifferenceValue().setRoomNum(roomNumDiff);
      	yearValue.getDifferenceValue().setParkingNum(parkingNumDiff);
      	yearValue.getDifferenceValue().setSaleArea(areaDiff);
      	yearValue.getDifferenceValue().setHousePrice(housePriceDiff);
      	yearValue.getDifferenceValue().setParkingPrice(parkingPriceDiff);
      	yearValue.getDifferenceValue().setTotalPrice(NumberUtils.BigDecimalADD(4, housePriceDiff,parkingPriceDiff));
      	yearValue.getDifferenceValue().setHouseAvgPrice(houseAvgPriceDiff);
      	yearValue.getDifferenceValue().setParkingAvgPrice(parkingAvgPriceDiff);
	}
	/**
	 * 
	 * @Description：月度对比 数据处理
	 * @author：yyd
	 * @date：2020年2月14日 下午2:56:28
	 */
	private void prepareMonthlyCompare(List<CompareDetailVO> budgetData,List<CompareDetailVO> dynamicData, String baseFullPathName,
			List<YearMonthComfirmVO> firstMonthlyValue, String month) {
		for(YearMonthComfirmVO yearMonthVo : firstMonthlyValue) {
			String monthTep = yearMonthVo.getYearMonth().split("-")[1];
			ComfirmBaseValueVO budgetValue = yearMonthVo.getBudgetValue();
			ComfirmBaseValueVO dynamicValue = yearMonthVo.getDynamicValue();
			ComfirmBaseValueVO differenceValue = yearMonthVo.getDifferenceValue();
			if(monthTep.equals(month)) {
				if(CollectionUtils.isNotEmpty(budgetData)) {
					for(CompareDetailVO budget : budgetData) {
						String fullPathName = budget.getOrgFullPathName();
						if(fullPathName.equals(baseFullPathName)) {
							budgetValue.setRoomNum(budget.getRoomNum());
							budgetValue.setParkingNum(budget.getParkingNum());
							budgetValue.setSaleArea(budget.getSaleArea());
							budgetValue.setHousePrice(budget.getHousePrice());
							budgetValue.setParkingPrice(budget.getParkingPrice());
							budgetValue.setTotalPrice(NumberUtils.BigDecimalADD(4, budget.getHousePrice(), budget.getParkingPrice()));
							budgetValue.setHouseAvgPrice(NumberUtils.divide(budget.getHousePrice(),budget.getSaleArea(),2));
							budgetValue.setParkingAvgPrice(NumberUtils.divide(budget.getParkingPrice(),budget.getParkingNum()==null?null:new BigDecimal(budget.getParkingNum()),2));
						}
					}
				}
				if(CollectionUtils.isNotEmpty(dynamicData)) {
					for(CompareDetailVO dynamic : dynamicData) {
						String fullPathName = dynamic.getOrgFullPathName();
						if(fullPathName.equals(baseFullPathName)) {
							dynamicValue.setRoomNum(dynamic.getRoomNum());
							dynamicValue.setParkingNum(dynamic.getParkingNum());
							dynamicValue.setSaleArea(dynamic.getSaleArea());
							dynamicValue.setHousePrice(dynamic.getHousePrice());
							dynamicValue.setParkingPrice(dynamic.getParkingPrice());
							dynamicValue.setTotalPrice(NumberUtils.BigDecimalADD(4, dynamic.getHousePrice(), dynamic.getParkingPrice()));
							dynamicValue.setHouseAvgPrice(NumberUtils.divide(dynamic.getHousePrice(),dynamic.getSaleArea(),2));
							dynamicValue.setParkingAvgPrice(NumberUtils.divide(dynamic.getParkingPrice(),dynamic.getParkingNum()==null?null:new BigDecimal(dynamic.getParkingNum()),2));
						}
					}
				}
			}
			//差异
			Integer budgetRoomNum = budgetValue.getRoomNum();
			Integer budgetParkingNum = budgetValue.getParkingNum();
			BigDecimal budgetSaleArea = budgetValue.getSaleArea();
			BigDecimal budgetHousePrice = budgetValue.getHousePrice();
			BigDecimal budgetParkingPrice = budgetValue.getParkingPrice();
			BigDecimal budgetHouseAvgPrice= budgetValue.getHouseAvgPrice();
			BigDecimal budgetParkingAvgPrice = budgetValue.getParkingAvgPrice();
			
			Integer dynamicRoomNum = dynamicValue.getRoomNum();
			Integer dynamicParkingNum = dynamicValue.getParkingNum();
			BigDecimal dynamicSaleArea = dynamicValue.getSaleArea();
			BigDecimal dynamicHousePrice = dynamicValue.getHousePrice();
			BigDecimal dynamicParkingPrice = dynamicValue.getParkingPrice();
			BigDecimal dynamicHouseAvgPrice= dynamicValue.getHouseAvgPrice();
			BigDecimal dynamicParkingAvgPrice = dynamicValue.getParkingAvgPrice();
			
			//房源套数差异
	      	Integer roomNumDiff = NumberUtils.IntegerSubtract(dynamicRoomNum,budgetRoomNum);
	      	Integer parkingNumDiff = NumberUtils.IntegerSubtract(dynamicParkingNum,budgetParkingNum);
	      	BigDecimal areaDiff = NumberUtils.subtract(dynamicSaleArea,budgetSaleArea);
	      	BigDecimal housePriceDiff = NumberUtils.subtract(dynamicHousePrice,budgetHousePrice);
	      	BigDecimal parkingPriceDiff = NumberUtils.subtract(dynamicParkingPrice,budgetParkingPrice);
	      	BigDecimal houseAvgPriceDiff = NumberUtils.subtract(dynamicHouseAvgPrice,budgetHouseAvgPrice);
	      	BigDecimal parkingAvgPriceDiff = NumberUtils.subtract(dynamicParkingAvgPrice,budgetParkingAvgPrice);
		
	      	differenceValue.setRoomNum(roomNumDiff);
	      	differenceValue.setParkingNum(parkingNumDiff);
	      	differenceValue.setSaleArea(areaDiff);
	      	differenceValue.setHousePrice(housePriceDiff);
	      	differenceValue.setParkingPrice(parkingPriceDiff);
	      	differenceValue.setTotalPrice(NumberUtils.BigDecimalADD(4, housePriceDiff,parkingPriceDiff));
	      	differenceValue.setHouseAvgPrice(houseAvgPriceDiff);
	      	differenceValue.setParkingAvgPrice(parkingAvgPriceDiff);
		}
	}
	/**
	 * 
	 * @Description：项目数层级合并
	 * @author：yyd
	 * @date：2020年2月11日 下午4:47:25
	 */
	private List<CompareDetailVO> mergeData(List<List<CompareDetailVO>> compareList) {
		List<CompareDetailVO> resList = Collections.synchronizedList(new ArrayList<>());
		List<CompareDetailVO> stageList = Collections.synchronizedList(new ArrayList<>());
		List<CompareDetailVO> groupList = Collections.synchronizedList(new ArrayList<>());
		List<CompareDetailVO> productList = Collections.synchronizedList(new ArrayList<>());
		if(CollectionUtils.isNotEmpty(compareList)) {
			for(List<CompareDetailVO> list : compareList) {
				for(CompareDetailVO detail : list) {
					 if(detail.getType().equals(OrgTypeEunm.ORG_STAGE.getKey())) {
		    			 stageList.add(detail);
		    		 }else if(detail.getType().equals(OrgTypeEunm.ORG_GROUP.getKey())) {
		    			 groupList.add(detail);
		    		 }else if(detail.getType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
		    			 productList.add(detail);
		    		 }
				}
			}
		}
		//分期去重
	   	stageList = stageList.stream().collect(
	               Collectors.collectingAndThen(
	                       Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompareDetailVO::getOrgFullPathName))), ArrayList::new));
	    //组团去重
	   	groupList = groupList.stream().collect(
	   			 Collectors.collectingAndThen(
	   					 Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompareDetailVO::getOrgFullPathName))), ArrayList::new));
	    //产品构成去重
	   	productList = productList.stream().collect(
	   			 Collectors.collectingAndThen(
	   					 Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompareDetailVO::getOrgFullPathName))), ArrayList::new));
	   	 //设置产品构成层级父级
		 for(CompareDetailVO p : productList) {
			 String fullPath = p.getOrgFullPathName();
			 for(CompareDetailVO g : groupList) {
				 String orgName = g.getOrgName();
				 if(fullPath.indexOf(orgName) != -1) {
					 p.setPid(g.getId());
					 break;
				 }
			 }
		 }
		 
		 //设置组团层级父级
		 for(CompareDetailVO g : groupList) {
			 String fullPath = g.getOrgFullPathName();
			 for(CompareDetailVO s : stageList) {
				 String orgName = s.getOrgName();
				 if(fullPath.indexOf(orgName) != -1) {
					 g.setPid(s.getId());
					 break;
				 }
			 }
		 }
		 
		 resList.addAll(stageList);
		 resList.addAll(groupList);
		 resList.addAll(productList);
		
		return resList;
	}

	/**
	 * 
	 * @Description：整合层级数据
	 * @author：yyd
	 * @date：2020年2月21日 上午1:02:42
	 */
	private List<CompareDetailVO> parpareData(List<DmDmSupplyCompareDetail> list,String deadline,String versionType, String month,String halfKey) {
		List<CompareDetailVO> resData = Collections.synchronizedList(new ArrayList<>());
		List<CompareDetailVO> productData = Collections.synchronizedList(new ArrayList<>());
		String projectId = "";
		if(CollectionUtils.isNotEmpty(list)) {
			projectId = list.get(0).getProjectId();
			//设置全路径
			setOrgFullPathName(list,projectId);
			
			if(versionType.equals(VersionTypeEunm.BUDGET.getKey())) {
				for(DmDmSupplyCompareDetail detail : list) {
					if(detail.getOrgType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
						if(detail.getVersionType().equals(VersionTypeEunm.BUDGET.getKey()) && detail.getVersionAttr().equals(VersionAttrEnum.BEFORE_WARPLAN.getKey())) {
								CompareDetailVO vo = new CompareDetailVO();
								vo.setId(UUIDUtils.create());
								vo.setPid(detail.getOrgPid());
								vo.setOrgId(detail.getOrgId());
								vo.setOrgCode(detail.getOrgCode());
								vo.setOrgName(detail.getOrgName());
								vo.setType(OrgTypeEunm.ORG_PRODUCT.getKey());
								vo.setOrgFullPathName(detail.getOrgFullPathName()+"-"+detail.getBusinessTypeName()+"-"+detail.getFreeTypeName()+"-"+detail.getProTypeName());
								vo.setBusinessType(detail.getBusinessType());
								vo.setBusinessTypeName(detail.getBusinessTypeName());
								vo.setFreeType(detail.getFreeType());
								vo.setFreeTypeName(detail.getFreeTypeName());
								vo.setProType(detail.getProType());
								vo.setProTypeName(detail.getProTypeName());
								vo.setProProductCode(detail.getProProductCode());
								vo.setProProductType(detail.getProProductType());
								String proProductCode = detail.getProProductCode();
							    if(StrUtils.isNotEmpty(proProductCode) && proProductCode.equals("139")) {
								 vo.setIsParking(1);
							    }else {
								 vo.setIsParking(0);
							    }
								//取数处理
								handleBuildData(detail,vo,deadline,month,versionType,halfKey);
								productData.add(vo);
						}else {
							List<CompareDetailVO> productList = parpareProductData(list,detail,deadline,month,halfKey,versionType);
							if(CollectionUtils.isNotEmpty(productList)) {
								productData.addAll(productList);
							}
						}
					}else if(detail.getOrgType().equals(OrgTypeEunm.ORG_GROUP.getKey())) {
						setGroupStageData(resData, detail,OrgTypeEunm.ORG_GROUP.getKey());
					}else if(detail.getOrgType().equals(OrgTypeEunm.ORG_STAGE.getKey())) {
						setGroupStageData(resData, detail,OrgTypeEunm.ORG_STAGE.getKey());
					}
				}
			}else {
				for(DmDmSupplyCompareDetail detail : list) {
					if(detail.getOrgType().equals(OrgTypeEunm.ORG_PRODUCT.getKey())) {
						List<CompareDetailVO> productList = parpareProductData(list,detail,deadline,month,halfKey,versionType);
						if(CollectionUtils.isNotEmpty(productList)) {
							productData.addAll(productList);
						}
					}else if(detail.getOrgType().equals(OrgTypeEunm.ORG_GROUP.getKey())) {
						setGroupStageData(resData, detail,OrgTypeEunm.ORG_GROUP.getKey());
					}else if(detail.getOrgType().equals(OrgTypeEunm.ORG_STAGE.getKey())) {
						setGroupStageData(resData, detail,OrgTypeEunm.ORG_STAGE.getKey());
					}
				}
			}
		}
		
		resData.addAll(productData);
		
		return resData;
	}
	/**
	 * 
	 * @Description：设置全路径
	 * @author：yyd
	 * @date：2020年2月21日 上午12:58:52
	 */
	private void setOrgFullPathName(List<DmDmSupplyCompareDetail> resData, String pId) {
		String fullPathName ="";
		for(DmDmSupplyCompareDetail dto : resData) {
			if(dto.getdId().equals(pId)) {
				fullPathName= dto.getOrgFullPathName();
			}
		}
		for(DmDmSupplyCompareDetail dto : resData) {
			if(dto.getOrgPid().equals(pId)) {
				dto.setOrgFullPathName(fullPathName+"/"+dto.getOrgName());
				setOrgFullPathName(resData,dto.getdId());
			}
		}
	}
	
	private boolean isSameYear(String year,LocalDateTime targetTime) {
		return targetTime != null && targetTime.getYear() == Integer.parseInt(year);
	}
	
	private boolean isSameMonth(String yearMonth,String targetDate) {
		return yearMonth.equals(targetDate);
	}
	
	private boolean isBetweenDate(LocalDateTime beginTime,LocalDateTime endTime,LocalDateTime targetTime) {
		return (targetTime.isAfter(beginTime) || targetTime.equals(beginTime)) && (targetTime.isBefore(endTime) || targetTime.equals(endTime));
	}
	/**
	 * 
	 * @Description：处理产品构成层级数据（最小颗粒度）
	 * @author：yyd
	 * @date：2020年2月21日 上午12:59:11
	 */
	private List<CompareDetailVO> parpareProductData(List<DmDmSupplyCompareDetail> list,DmDmSupplyCompareDetail detail, String deadline,
			String month, String halfKey,String versionType) {
		List<DmDmSupplyCompareDetail> tempList = Collections.synchronizedList(new ArrayList<>());
		String year = deadline.split("-")[0];
		if(CollectionUtils.isEmpty(list)) {
			return new ArrayList<>();
		}
		if(StrUtils.isEmpty(month) && StrUtils.isEmpty(halfKey)) {
			//年度
			if(CollectionUtils.isNotEmpty(list)) {
				for(DmDmSupplyCompareDetail obj : list) {
					if(obj.getOrgPid().equals(detail.getdId())) {
						String bussnessType =obj.getBusinessType();
						if(StrUtils.isNotEmpty(bussnessType) && isValid(bussnessType)) {
							if(versionType.equals(VersionTypeEunm.BUDGET.getKey())) {
								LocalDateTime planDate = obj.getPlanSupplyDate();
								if(planDate != null && isSameYear(year,planDate)) {
									tempList.add(obj);
								}
							}else {
								LocalDateTime actualTime = obj.getSupplyTimeVirtual() == null ? obj.getActualSupplyDate() : obj.getSupplyTimeVirtual(); 
								if(actualTime != null && isSameYear(year,actualTime)) {
									tempList.add(obj);
									continue;
								}
								LocalDateTime planDate = obj.getPlanSupplyDate();
								if(planDate != null && isSameYear(year,planDate)) {
									tempList.add(obj);
								}
							}
						}
					}
				}
			}
		}else if(StrUtils.isEmpty(month) && StrUtils.isNotEmpty(halfKey)){
			//半年度
			String begin ="";
			String end = "";
			if(halfKey.equals(FIRST_HALF_YEAR_KEY)) {
				begin = year+"-01";
				end = year+"-06";
			}else {
				begin = year+"-07";
				end = year+"-12";
			}
			LocalDateTime beginTime = LocalDateTimeUtils.toLocalDateTime(begin);
			LocalDateTime endTime = LocalDateTimeUtils.toLocalDateTime(end);
			if(CollectionUtils.isNotEmpty(list)) {
				for(DmDmSupplyCompareDetail obj : list) {
					if(obj.getOrgPid().equals(detail.getdId())) {
						String bussnessType =obj.getBusinessType();
						if(StrUtils.isNotEmpty(bussnessType) && isValid(bussnessType)) {
							if(versionType.equals(VersionTypeEunm.BUDGET.getKey())) {
								LocalDateTime planDate = obj.getPlanSupplyDate();
								if(planDate != null) {
									LocalDateTime supplyDateTime = LocalDateTimeUtils.toLocalDateTime(LocalDateTimeUtils.formatTime(planDate, "yyyy-MM"));
									if(isBetweenDate(beginTime,endTime,supplyDateTime)) {
										tempList.add(obj);
									}
								}
							}else {
								LocalDateTime actualTime = obj.getSupplyTimeVirtual() == null ? obj.getActualSupplyDate() : obj.getSupplyTimeVirtual(); 
								if(actualTime != null) {
									LocalDateTime actualDateTime = LocalDateTimeUtils.toLocalDateTime(LocalDateTimeUtils.formatTime(actualTime, "yyyy-MM"));
									if(isBetweenDate(beginTime,endTime,actualDateTime)) {
										tempList.add(obj);
										continue;
									}
								}
								LocalDateTime planDate = obj.getPlanSupplyDate();
								if(planDate != null) {
									LocalDateTime supplyDateTime = LocalDateTimeUtils.toLocalDateTime(LocalDateTimeUtils.formatTime(planDate, "yyyy-MM"));
									if(isBetweenDate(beginTime,endTime,supplyDateTime)) {
										tempList.add(obj);
									}
								}
							}
						}
					}
				}
			}
		}else {
			//月度
			String yearMonth = year+"-"+month;
			if(CollectionUtils.isNotEmpty(list)) {
				for(DmDmSupplyCompareDetail obj : list) {
					if(obj.getOrgPid().equals(detail.getdId())) {
						String bussnessType =obj.getBusinessType();
						if(StrUtils.isNotEmpty(bussnessType) && isValid(bussnessType)) {
							if(versionType.equals(VersionTypeEunm.BUDGET.getKey())) {
								LocalDateTime planDate = obj.getPlanSupplyDate();
								if(planDate != null) {
									String planTime = LocalDateTimeUtils.formatTime(planDate, "yyyy-MM");
									if(planTime.equals(yearMonth)) {
										tempList.add(obj);
									}
								}
							}else {
								LocalDateTime actualTime = obj.getSupplyTimeVirtual() == null ? obj.getActualSupplyDate() : obj.getSupplyTimeVirtual(); 
								if(actualTime != null) {
									String actualDateTime = LocalDateTimeUtils.formatTime(actualTime, "yyyy-MM");
									if(actualDateTime.equals(yearMonth)) {
										tempList.add(obj);
										continue;
									}
								}
								LocalDateTime planDate = obj.getPlanSupplyDate();
								if(planDate != null) {
									String planTime = LocalDateTimeUtils.formatTime(planDate, "yyyy-MM");
									if(planTime.equals(yearMonth)) {
										tempList.add(obj);
									}
								}
							}
						}
					}
				}
			}
			
		}
		
		List<CompareDetailVO> productList = Collections.synchronizedList(new ArrayList<>());
		List<CompareDetailVO>  res = Collections.synchronizedList(new ArrayList<>());
		//数据合并
		if(CollectionUtils.isNotEmpty(tempList)) {
			for(DmDmSupplyCompareDetail dto : tempList ) {
				CompareDetailVO vo = new CompareDetailVO();
				vo.setId(UUIDUtils.create());
				vo.setPid(detail.getOrgPid());
				vo.setOrgId(detail.getOrgId());
				vo.setOrgCode(detail.getOrgCode());
				vo.setOrgName(detail.getOrgName());
				vo.setType(OrgTypeEunm.ORG_PRODUCT.getKey());
				vo.setOrgFullPathName(detail.getOrgFullPathName()+"-"+dto.getBusinessTypeName()+"-"+dto.getFreeTypeName()+"-"+dto.getProTypeName());
				vo.setBusinessType(dto.getBusinessType());
				vo.setBusinessTypeName(dto.getBusinessTypeName());
				vo.setFreeType(dto.getFreeType());
				vo.setFreeTypeName(dto.getFreeTypeName());
				vo.setProType(dto.getProType());
				vo.setProTypeName(dto.getProTypeName());
				vo.setProProductCode(detail.getProProductCode());
				vo.setProProductType(detail.getProProductType());
				String proProductCode = detail.getProProductCode();
			    if(StrUtils.isNotEmpty(proProductCode) && proProductCode.equals("139")) {
				 vo.setIsParking(1);
			    }else {
				 vo.setIsParking(0);
			    }
				//取数处理
				handleBuildData(dto,vo,deadline,month,versionType,halfKey);
				productList.add(vo);
			}
			//产品构成去重
		    res = mergeProductData(productList,detail);
		}
		return res;
	}
	
	private List<CompareDetailVO> mergeProductData(List<CompareDetailVO> tempList,DmDmSupplyCompareDetail detail) {
		List<CompareDetailVO> lastList = Collections.synchronizedList(new ArrayList<>());
		for(CompareDetailVO de : tempList) {
			de.setTempOrgNames(de.getBusinessTypeName()+"-"+de.getFreeTypeName()+"-"+de.getProTypeName());
		}
		//去重
		List<CompareDetailVO> resList = tempList.stream().collect(
	               Collectors.collectingAndThen(
	                       Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompareDetailVO::getTempOrgNames))), ArrayList::new));
		
		if(tempList.size() == resList.size()) {
			return resList;
		}
		
		for(CompareDetailVO detailVo : resList) {
			CompareDetailVO vo = new CompareDetailVO();
			vo.setId(UUIDUtils.create());
			vo.setPid(detail.getOrgPid());
			vo.setOrgId(detail.getOrgId());
			vo.setOrgCode(detail.getOrgCode());
			vo.setOrgName(detail.getOrgName());
			vo.setProProductCode(detail.getProProductCode());
			vo.setProProductType(detail.getProProductType());
			vo.setType(OrgTypeEunm.ORG_PRODUCT.getKey());
			vo.setOrgFullPathName(detail.getOrgFullPathName()+"-"+detailVo.getBusinessTypeName()+"-"+detailVo.getFreeTypeName()+"-"+detailVo.getProTypeName());
			String proProductCode = detail.getProProductCode();
		    if(StrUtils.isNotEmpty(proProductCode) && proProductCode.equals("139")) {
			 vo.setIsParking(1);
		    }else {
			 vo.setIsParking(0);
		    }
			vo.setBusinessType(detailVo.getBusinessType());
			vo.setBusinessTypeName(detailVo.getBusinessTypeName());
			vo.setFreeType(detailVo.getFreeType());
			vo.setFreeTypeName(detailVo.getFreeTypeName());
			vo.setProType(detailVo.getProType());
			vo.setProTypeName(detailVo.getProTypeName());
			lastList.add(vo);
		}
		
		//重新设值
		for(CompareDetailVO obj : lastList) {
			Integer isParking = obj.getIsParking();
			for(CompareDetailVO detailVo : tempList) {
				if(obj.getOrgFullPathName().equals(detailVo.getOrgFullPathName())) {
					obj.setRoomNum(NumberUtils.intADD(obj.getRoomNum(), detailVo.getRoomNum()));
					obj.setParkingNum(NumberUtils.intADD(obj.getParkingNum(), detailVo.getParkingNum()));
					if(isParking != null && isParking.intValue() == 0) {
						obj.setSaleArea(NumberUtils.BigDecimalADD(4, obj.getSaleArea(), detailVo.getSaleArea()));
					}
					obj.setHousePrice(NumberUtils.BigDecimalADD(4, obj.getHousePrice(), detailVo.getHousePrice()));
					obj.setParkingPrice(NumberUtils.BigDecimalADD(4, obj.getParkingPrice(), detailVo.getParkingPrice()));
				}
			}
		}
		return lastList;
	}
	
	private void handleBuildData(DmDmSupplyCompareDetail dto,CompareDetailVO vo,String deadline,String month,String versionType,String halfKey) {
		String year = deadline.split("-")[0];
		int baseMonth = Integer.parseInt(deadline.split("-")[1]);
		int baseYearMonth = LocalDateTimeUtils.toIntYearMonth(Integer.valueOf(year), baseMonth);
		//半年度数据
		String begin ="";
		String end = "";
		if(halfKey.equals(FIRST_HALF_YEAR_KEY)) {
			begin = year+"-01";
			end = year+"-06";
		}else {
			begin = year+"-07";
			end = year+"-12";
		}
		LocalDateTime beginTime = LocalDateTimeUtils.toLocalDateTime(begin);
		LocalDateTime endTime = LocalDateTimeUtils.toLocalDateTime(end);
		
		LocalDateTime supplyDate = dto.getPlanSupplyDate();
		LocalDateTime supplyDateActual = dto.getSupplyTimeVirtual() == null ? dto.getActualSupplyDate() : dto.getSupplyTimeVirtual();
		if(supplyDate != null) {
			int planSupplyDate = LocalDateTimeUtils.toIntYearMonth(supplyDate.getYear(), supplyDate.getMonthValue());
			int beginDate = LocalDateTimeUtils.toIntYearMonth(beginTime.getYear(), beginTime.getMonthValue());
			
			if(versionType.equals(VersionTypeEunm.BUDGET.getKey())) {
				//预算版-年度取数（计划合计）
				setPlanValue(dto,vo);
			}else {
				//动态版-年度取数（当前月份及之前取实际，当前月份以后取计划）
				if(StrUtils.isEmpty(month) && StrUtils.isEmpty(halfKey)) {
					if(isSameYear(year,supplyDate)) {
						if(supplyDateActual != null) {
							int actualSupplyDate = LocalDateTimeUtils.toIntYearMonth(supplyDateActual.getYear(), supplyDateActual.getMonthValue());
							if(isSameYear(year,supplyDateActual) && actualSupplyDate <= baseYearMonth) {
								setActualValue(dto,vo);
							}
						}else {
							if(planSupplyDate <= baseYearMonth) {
								setActualValue(dto,vo);
							}else {
								setPlanValue(dto,vo);
							}
						}
					}else {
						if(supplyDateActual != null) {
							int actualSupplyDate = LocalDateTimeUtils.toIntYearMonth(supplyDateActual.getYear(), supplyDateActual.getMonthValue());
							if(isSameYear(year,supplyDateActual) && actualSupplyDate <= baseYearMonth) {
								setActualValue(dto,vo);
							}else {
								setPlanValue(dto,vo);
							}
						}
					}
				}else if(StrUtils.isEmpty(month) && StrUtils.isNotEmpty(halfKey)){
					//动态版-上半年度取数（取实际）
					if(halfKey.equals(FIRST_HALF_YEAR_KEY)) {
						if(supplyDateActual != null) {
							LocalDateTime actualDateTime = LocalDateTimeUtils.toLocalDateTime(LocalDateTimeUtils.formatTime(supplyDateActual, "yyyy-MM"));
							if(isBetweenDate(beginTime, endTime,actualDateTime)) {
								setActualValue(dto,vo);
							}
						}
					}else {
						//动态版-下半年度取数（当前月份及之前取实际，当前月份以后取计划）
						if(planSupplyDate > baseYearMonth) {
							if(supplyDateActual != null) {
								int actualSupplyDate = LocalDateTimeUtils.toIntYearMonth(supplyDateActual.getYear(), supplyDateActual.getMonthValue());
								if(actualSupplyDate <= baseYearMonth && actualSupplyDate >= beginDate) {
									setActualValue(dto,vo);
								}else {
									setPlanValue(dto,vo);
								}
							}else {
								setPlanValue(dto,vo);
							}
						}else {
							if(supplyDateActual != null) {
								int actualSupplyDate = LocalDateTimeUtils.toIntYearMonth(supplyDateActual.getYear(), supplyDateActual.getMonthValue());
								if(actualSupplyDate <= baseYearMonth && actualSupplyDate >= beginDate) {
									setActualValue(dto,vo);
								}
							}
						}
					}
				}else {
					//动态版-月度取数（当前月份之前取实际，当前月份及以后取计划）
					//月度数据
					String yearMonth = year+"-"+month;
					int showYearMonth = LocalDateTimeUtils.toIntYearMonth(Integer.valueOf(year), Integer.valueOf(month));
					if(showYearMonth < baseYearMonth) {
						if(supplyDateActual != null) {
							String supplyTimeActual =  LocalDateTimeUtils.formatTime(supplyDateActual, "yyyy-MM");
							if(isSameMonth(yearMonth,supplyTimeActual)) {
								setActualValue(dto,vo);
							}
						}
					}else {
						if(supplyDate != null) {
							String supplyTime =  LocalDateTimeUtils.formatTime(supplyDate, "yyyy-MM");
							if(isSameMonth(yearMonth, supplyTime)) {
								setPlanValue(dto,vo);
							}
						}
					}
					
				}
			}
		
		}
	}
	
	/**
	 * 
	 * @Description：获取计划值
	 * @author：yyd
	 * @date：2020年2月14日 上午10:02:41
	 */
	private void setPlanValue(DmDmSupplyCompareDetail dto,CompareDetailVO vo) {
		vo.setRoomNum(dto.getRoomNum());
		vo.setParkingNum(dto.getParkingNum());
		if(vo.getIsParking() != null && vo.getIsParking().intValue() == 0) {
			vo.setSaleArea(dto.getSaleArea());
		}
		vo.setHousePrice(dto.getHouseCommodityValue());
		vo.setParkingPrice(dto.getNotCommodityValue());
	}
	/**
	 * 
	 * @Description：获取实际值
	 * @author：yyd
	 * @date：2020年2月14日 上午10:02:41
	 */
	private void setActualValue(DmDmSupplyCompareDetail dto,CompareDetailVO vo) {
		vo.setRoomNum(dto.getRoomNumActual());
		vo.setParkingNum(dto.getParkingNumActual());
		if(vo.getIsParking() != null && vo.getIsParking().intValue() == 0) {
			vo.setSaleArea(dto.getAreaActual());
		}
		vo.setHousePrice(dto.getHouseCommodityValueActual());
		vo.setParkingPrice(dto.getNotCommodityValueActual());
	}
	
	private void setGroupStageData(List<CompareDetailVO> resData,DmDmSupplyCompareDetail detail,String orgType) {
		CompareDetailVO vo = new CompareDetailVO();
		vo.setId(detail.getdId());
		vo.setPid(detail.getOrgPid());
		vo.setOrgId(detail.getOrgId());
		vo.setOrgCode(detail.getOrgCode());
		vo.setOrgName(detail.getOrgName());
		vo.setType(detail.getOrgType());
		vo.setOrgFullPathName(detail.getOrgFullPathName());
		if(orgType.equals(OrgTypeEunm.ORG_STAGE.getKey())) {
			vo.setStageName(detail.getStageName());
			vo.setStageCode(detail.getStageCode());
			vo.setEquityRatio(detail.getEquityRatio());
			vo.setTradersWay(detail.getIsOpMarketing());
			vo.setIsMergeTable(detail.getIsAndTable());
			vo.setPendingHomeSale(detail.getExistRoomSale());
		}else if(orgType.equals(OrgTypeEunm.ORG_GROUP.getKey())) {
			vo.setGroupName(detail.getOrgName());
		}
		resData.add(vo);
	}

	List<ProjectByStages> parentList = null;
	@Override
	public Object getProjectParentLevel(String projectId) {
		parentList = new ArrayList<>();
		List<ProjectByStages> allOrgList = dmDmSupplyCompareDetailMapper.selectProjectParentList();
		getParentLevel(projectId,allOrgList);
		return parentList;
	}
	
	private void getParentLevel(String id,List<ProjectByStages> orgList){
		if(CollectionUtils.isNotEmpty(orgList)) {
			for(ProjectByStages org : orgList) {
				String orgId = org.getOrgdepid();
				if(orgId.equals(id)) {
					String pId = org.getParentOrgid();
					parentList.add(org);
					getParentLevel(pId,orgList);
				}
			}
		}
	}
	
}
